package com.qianji.service.impl;

import com.qianji.mapper.ThirdPartyMapper;
import com.qianji.mapper.UserMapper;
import com.qianji.pojo.AdPlaceDto;
import com.qianji.pojo.ThirdPartyDto;
import com.qianji.pojo.UserDto;
import com.qianji.service.ThirdPartyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 钟丽诗
 * @Date 2021.4.19
 */

@Slf4j
@Service
public class ThirdPartyServiceImpl implements ThirdPartyService {

    @Autowired
    private ThirdPartyMapper thirdPartyMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public ThirdPartyDto findLink(Long id) {
        return thirdPartyMapper.findLink(id);
    }

    @Override
    public AdPlaceDto findPlace(Long id) {
        return thirdPartyMapper.findPlace(id);
    }

    @Override
    public List<ThirdPartyDto> findThirdParty(Long id, Integer number) {

        List<ThirdPartyDto> list = null;

        if(id == null){
            log.info("用户id未传入");
            return null;
        }
        UserDto user = userMapper.findByPanId(id);
        log.info("user==============>{}",user);
        if(user == null){
            log.info("数据库中不存在该用户");
            return  null;
        }

        if(user.getUserType() == 0){//超级用户，自己的
            list = thirdPartyMapper.findByPanId(id,number);
        }else{//给流量主的(如：菜鸟)
            list = thirdPartyMapper.findToRests(id,number);
        }
        log.info("ThirdPartyDto==============>{}",list);
        return list;
    }

}
